home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2257 / 2257.xpi / chrome / content / imtranslatorOverlay.js < prev    next >
Text File  |  2010-01-06  |  13KB  |  429 lines

  1.  
  2. var com_smartlinkcorp_imtranslator = new Object();
  3. var ImTranslator_PrefsOnLoad = Components.classes["@mozilla.org/preferences-service;1"]
  4.                       .getService(Components.interfaces.nsIPrefService)
  5.                       .getBranch("imtranslator.");
  6.  
  7.  
  8. // This launches the Translator
  9. //
  10. var temptext="";
  11. com_smartlinkcorp_imtranslator.launchTranslator= function () {
  12.  
  13.  
  14.  
  15. /*var node = TextEditorLib.getNode();
  16. if (node!=null || !TextEditorLib.isObjectEmpty(TextEditorLib.getSelection(null))) 
  17. {
  18.     if (node==null || TextEditorLib.isNodeEditor(node)) 
  19.     {
  20.             // transform text in an HTML document or HTML editor
  21.             temptext = TextEditorLib.getSelection(node);
  22.     }
  23. }*/
  24.  
  25. TextEditorLib.transformSelectionText(com_smartlinkcorp_imtranslator.SetTextforTrans, true, true);
  26.  
  27.  
  28. if (!ImTranslator_PrefsOnLoad.getCharPref("dirParentFrom") && !ImTranslator_PrefsOnLoad.getCharPref("dirParentTo")) {
  29.     ImTranslator_PrefsOnLoad.setCharPref("dirParentFrom","en");
  30.     ImTranslator_PrefsOnLoad.setCharPref("dirParentTo","es");
  31. }
  32. var newDir = ImTranslator_PrefsOnLoad.getCharPref("dirParentFrom")+"/"+ImTranslator_PrefsOnLoad.getCharPref("dirParentTo");
  33.  
  34. if (!ImTranslator_PrefsOnLoad.getCharPref("locParent")) var newLoc = ImTranslator_PrefsOnLoad.setCharPref("locParent","en");
  35. else var newLoc = ImTranslator_PrefsOnLoad.getCharPref("locParent");
  36.  
  37.  
  38. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoDetect")) var adet = 0;
  39. else var adet = 1;
  40.  
  41. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoBack")) var ab = 0;
  42. else var ab = 1;
  43.  
  44. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoTranslit")) var at = 0;
  45. else var at = 1;
  46.  
  47. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoSpell")) var a_s = 0;
  48. else var a_s = 1;
  49.  
  50. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoDecode")) var ad = 0;
  51. else var ad = 1;
  52.  
  53. if (!ImTranslator_PrefsOnLoad.getBoolPref("GoogleOnly")) var gon = 0;
  54. else var gon = 1;
  55.  
  56. if (!ImTranslator_PrefsOnLoad.getBoolPref("AutoDictionary")) var adi = 0;
  57. else var adi = 1;
  58.  
  59.  
  60. var translatorURL = "http://translation.paralink.com/translator.asp?op=y&adet="+adet+"&a_s="+a_s+"&ad="+ad+"&ab="+ab+"&at="+at+"&gon="+gon+"&adi="+adi+"&dir="+newDir+"&loc="+newLoc+"&text="+escape(temptext);
  61.  
  62. temptext="";                                          
  63. var features = "unadorned=yes,dependent=yes,width=480,height=470,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  64.  
  65.  
  66.  
  67. //PLwindow.close();
  68.  
  69.  
  70.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  71.     .getService(Components.interfaces.nsIWindowMediator);  
  72.  var type="navigator:browser";
  73.  
  74.  var enumerator = wm.getEnumerator(type); 
  75.  
  76.  while(enumerator.hasMoreElements()) {  
  77.    var win = enumerator.getNext();
  78.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  79.  
  80.              //     tabbrowser = win.Browser(); 
  81.  
  82.      win.close();
  83.  }
  84.  
  85.  
  86.  
  87. //    var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  88. //    .getService(Components.interfaces.nsIWindowWatcher); 
  89.  
  90.    // var win = wm.getMostRecentWindow(type);  
  91.  
  92. //win.open(translatorURL,"translator",features);
  93.      //if(!win.closed)win.close();
  94.      window.open(translatorURL,"translator",features);
  95.  
  96.  
  97.  
  98. //var features = "z-lock:yes;modal:no;unadorned=yes;center=yes;scroll=no;help=no;status=no;resizable=no;edge=sunken;dialogWidth=520;dialogHeight=520";
  99. //window.showModalDialog(translatorURL,"",features);
  100.  
  101.  
  102.  
  103.  
  104. }
  105.  
  106.  
  107. com_smartlinkcorp_imtranslator.ToolsTranslator = function ()
  108. {
  109.  
  110.  
  111. TextEditorLib.transformSelectionText(com_smartlinkcorp_imtranslator.SetTextforTrans, true, true);
  112.  
  113. var newDir = ImTranslator_PrefsOnLoad.getCharPref("dirParentFrom")+"/"+ImTranslator_PrefsOnLoad.getCharPref("dirParentTo");
  114.  
  115. if (!ImTranslator_PrefsOnLoad.getCharPref("locParent")) var newLoc = ImTranslator_PrefsOnLoad.setCharPref("locParent","en");
  116. else var newLoc = ImTranslator_PrefsOnLoad.getCharPref("locParent");
  117.  
  118. var translatorURL = "http://translation.imtranslator.net/widget2/?dir="+newDir+"&loc="+newLoc+"&text="+escape(temptext);
  119.  
  120.  
  121. temptext="";                                          
  122. var features = "unadorned=yes,dependent=yes,width=336,height=390,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  123.  
  124.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  125.     .getService(Components.interfaces.nsIWindowMediator);  
  126.  var type="navigator:browser";
  127.  
  128.  var enumerator = wm.getEnumerator(type); 
  129.  
  130.  while(enumerator.hasMoreElements()) {  
  131.    var win = enumerator.getNext();
  132.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  133.  
  134.              //     tabbrowser = win.Browser(); 
  135.  
  136.      win.close();
  137.  }
  138.  
  139.  window.open(translatorURL,"translator",features);
  140.  
  141.  
  142. }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. com_smartlinkcorp_imtranslator.ToolsTTS = function ()
  152. {
  153.  
  154. TextEditorLib.transformSelectionText(com_smartlinkcorp_imtranslator.SetTextforTrans, true, true);
  155.  
  156. var newDir = ImTranslator_PrefsOnLoad.getCharPref("dirParentFrom");
  157.  
  158.  
  159. var translatorURL = "http://free-translator.imtranslator.net/tts-468.asp?dir="+newDir+"&text="+escape(temptext);
  160.  
  161. temptext="";                                          
  162. var features = "unadorned=yes,dependent=yes,width=470,height=485,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  163.  
  164.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  165.     .getService(Components.interfaces.nsIWindowMediator);  
  166.  var type="navigator:browser";
  167.  
  168.  var enumerator = wm.getEnumerator(type); 
  169.  
  170.  while(enumerator.hasMoreElements()) {  
  171.    var win = enumerator.getNext();
  172.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  173.  
  174.              //     tabbrowser = win.Browser(); 
  175.  
  176.      win.close();
  177.  }
  178.  
  179.  window.open(translatorURL,"translator",features);
  180.  
  181.  
  182. }
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. com_smartlinkcorp_imtranslator.ToolsVirk = function ()
  193. {
  194.  
  195. var translatorURL = "http://widget.imtranslator.net/virk.asp";
  196.  
  197. temptext="";                                          
  198. var features = "unadorned=yes,dependent=yes,width=310,height=350,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  199.  
  200.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  201.     .getService(Components.interfaces.nsIWindowMediator);  
  202.  var type="navigator:browser";
  203.  
  204.  var enumerator = wm.getEnumerator(type); 
  205.  
  206.  while(enumerator.hasMoreElements()) {  
  207.    var win = enumerator.getNext();
  208.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  209.  
  210.              //     tabbrowser = win.Browser(); 
  211.  
  212.      win.close();
  213.  }
  214.  
  215.  window.open(translatorURL,"translator",features);
  216.  
  217.  
  218. }
  219.  
  220.  
  221.  
  222.  
  223. com_smartlinkcorp_imtranslator.ToolsDictionary = function ()
  224. {
  225.  
  226. TextEditorLib.transformSelectionText(com_smartlinkcorp_imtranslator.SetTextforTrans, true, true);
  227.  
  228. var newDir = ImTranslator_PrefsOnLoad.getCharPref("dirParentFrom")+"/"+ImTranslator_PrefsOnLoad.getCharPref("dirParentTo");
  229.  
  230. var translatorURL = "http://dictionary.paralink.com/gadget.asp?lang="+newDir+"&text="+escape(temptext);
  231.  
  232. temptext="";                                          
  233. var features = "unadorned=yes,dependent=yes,width=320,height=350,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  234.  
  235.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  236.     .getService(Components.interfaces.nsIWindowMediator);  
  237.  var type="navigator:browser";
  238.  
  239.  var enumerator = wm.getEnumerator(type); 
  240.  
  241.  while(enumerator.hasMoreElements()) {  
  242.    var win = enumerator.getNext();
  243.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  244.  
  245.              //     tabbrowser = win.Browser(); 
  246.  
  247.      win.close();
  248.  }
  249.  
  250.  window.open(translatorURL,"translator",features);
  251.  
  252.  
  253. }
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. com_smartlinkcorp_imtranslator.ChortCutToOptions = function ()
  264. {
  265.  
  266. var translatorURL = "chrome://imtranslator/content/options.xul";
  267.  
  268. temptext="";                                          
  269. //var features = "unadorned=yes,dependent=yes,width=480,height=470,scroll=no,help=no,status=no,directories=no,menubar=no,resizable=no";
  270. //var features = "unadorned:yes;dependent:yes;dialogWidth:480px;dialogHeight:470px,scroll:no,help:no,status:no,directories:no,menubar:no,resizable:no";
  271. var features = "dialogWidth:480px;dialogHeight:470px";
  272.  
  273.  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  274.     .getService(Components.interfaces.nsIWindowMediator);  
  275.  var type="navigator:browser";
  276.  
  277.  var enumerator = wm.getEnumerator(type); 
  278.  
  279.  while(enumerator.hasMoreElements()) {  
  280.    var win = enumerator.getNext();
  281.    if(win.document.title.indexOf("Free translation, ImTranslator.com")>-1)
  282.  
  283.              //     tabbrowser = win.Browser(); 
  284.  
  285.      win.close();
  286.  }
  287.  
  288.  //window.open(translatorURL,"translator",features);
  289.    window.showModalDialog(translatorURL,"translator",features);
  290.  
  291. }
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. com_smartlinkcorp_imtranslator.SetTextforTrans= function (text,RangeState){
  299. temptext += text;
  300. }
  301.  
  302. com_smartlinkcorp_imtranslator.imtranslator_shutdown = function (){
  303.  ImTranslator_PrefsOnLoad.removeObserver("", watcher);
  304. }
  305. var watcher={
  306. observe: function(subject, topic, data)
  307.    {
  308.  
  309.      if (topic != "nsPref:changed")
  310.      {
  311.        return;
  312.      }
  313.  
  314.      switch(data)
  315.      {
  316.        case "showBut":
  317.         if(!ImTranslator_PrefsOnLoad.getBoolPref("showBut")){
  318.  
  319.     var tbutton = document.getElementById("translator-toolbar-button");
  320.     tbutton.parentNode.removeChild(tbutton);
  321.     }
  322.     else com_smartlinkcorp_imtranslator.loadtest();
  323.          break;
  324.      }
  325.  },
  326. }
  327.  
  328. com_smartlinkcorp_imtranslator.loadtest = function ()
  329. {
  330.  
  331.  
  332.  
  333.  
  334.      ImTranslator_PrefsOnLoad.QueryInterface(Components.interfaces.nsIPrefBranch2);
  335.      ImTranslator_PrefsOnLoad.addObserver("", watcher, false);
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("showBut"))      ImTranslator_PrefsOnLoad.setBoolPref("showBut",true);
  343.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("locParent"))     ImTranslator_PrefsOnLoad.setCharPref("locParent","en");  
  344.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("dirParentFrom"))    ImTranslator_PrefsOnLoad.setCharPref("dirParentFrom","en");
  345.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("dirParentTo"))    ImTranslator_PrefsOnLoad.setCharPref("dirParentTo","es");
  346.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoDetect"))    ImTranslator_PrefsOnLoad.setBoolPref("AutoDetect",false);
  347.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoBack"))        ImTranslator_PrefsOnLoad.setBoolPref("AutoBack",false);
  348.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoSpell"))    ImTranslator_PrefsOnLoad.setBoolPref("AutoSpell",false);
  349.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoDecode"))    ImTranslator_PrefsOnLoad.setBoolPref("AutoDecode",this.false);
  350.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoTranslit"))    ImTranslator_PrefsOnLoad.setBoolPref("AutoTranslit",false);
  351.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("GoogleOnly"))    ImTranslator_PrefsOnLoad.setBoolPref("GoogleOnly",false);
  352.     if (!ImTranslator_PrefsOnLoad.prefHasUserValue("AutoDictionary"))    ImTranslator_PrefsOnLoad.setBoolPref("AutoDictionary",false);
  353.  
  354.  
  355.  
  356. //alert(ImTranslator_PrefsOnLoad.prefHasUserValue("showBut"));
  357. //if(ImTranslator_PrefsOnLoad.prefHasUserValue("showBut")) {
  358. //  alert(ImTranslator_PrefsOnLoad.getBoolPref("showBut"));
  359. //}
  360.  
  361.  
  362.  
  363.  
  364.  
  365.      if(!ImTranslator_PrefsOnLoad.getBoolPref("showBut")){
  366.          var tbutton = document.getElementById("translator-toolbar-button");
  367.          tbutton.parentNode.removeChild(tbutton);  
  368.      }
  369.  
  370.  
  371.       var toolbox = document.getElementById("navigator-toolbox");
  372.       
  373.       var toolboxDocument = toolbox.ownerDocument;
  374.       var hasAddbutton = false, hasmyPageButton = false;
  375.  
  376.       
  377. for (var i = 0; i < toolbox.childNodes.length; ++i) {
  378.         
  379.         var toolbar = toolbox.childNodes[i];
  380.           
  381.           if (toolbar.localName == "toolbar" && toolbar.getAttribute("customizable")=="true") {          
  382.             
  383.             if(toolbar.currentSet.indexOf("translator-toolbar-button")>-1)
  384.               hasmyPageButton = true;
  385.                   
  386.           }
  387.       }
  388.  
  389.  
  390.  
  391. if(!hasmyPageButton && ImTranslator_PrefsOnLoad.getBoolPref("showBut")){
  392. for (var i = 0; i < toolbox.childNodes.length; ++i) {
  393.       toolbar = toolbox.childNodes[i];
  394.  
  395.       if (toolbar.localName == "toolbar" &&  toolbar.getAttribute("customizable")=="true" && toolbar.id=="nav-bar") 
  396.       {              
  397.             var newSet = "";
  398.             var child = toolbar.firstChild;
  399.             var hasAddButtonVisited = false;
  400.             while(child){               
  401.     
  402.         if(!hasmyPageButton && (child.id=="translator-toolbar-button" || child.id=="urlbar-container")){
  403.                   newSet += "translator-toolbar-button,";
  404.               hasmyPageButton = true;
  405.           }  
  406.               newSet += child.id+",";
  407.               child = child.nextSibling;
  408.             }
  409.         
  410.             newSet = newSet.substring(0, newSet.length-1);
  411.             toolbar.currentSet = newSet;
  412.  
  413.             toolbar.setAttribute("currentset", newSet);
  414.             toolboxDocument.persist(toolbar.id, "currentset");
  415.             BrowserToolboxCustomizeDone(true);
  416.  
  417.             break; 
  418.     }
  419. }
  420.  
  421. }
  422.  
  423.  
  424. }
  425.  
  426.  
  427.  
  428.  
  429.